home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2009 December / maximum-cd-2009-12.iso / DiscContents / gimp-2.7.0-i686-setup.exe / {app} / share / gimp / 2.0 / scripts / truchet.scm < prev    next >
Encoding:
GIMP Script-Fu Script  |  2009-08-19  |  5.8 KB  |  172 lines

  1. ; GIMP - The GNU Image Manipulation Program
  2. ; Copyright (C) 1995 Spencer Kimball and Peter Mattis
  3. ;
  4. ; This program is free software: you can redistribute it and/or modify
  5. ; it under the terms of the GNU General Public License as published by
  6. ; the Free Software Foundation; either version 3 of the License, or
  7. ; (at your option) any later version.
  8. ;
  9. ; This program is distributed in the hope that it will be useful,
  10. ; but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12. ; GNU General Public License for more details.
  13. ;
  14. ; You should have received a copy of the GNU General Public License
  15. ; along with this program.  If not, see <http://www.gnu.org/licenses/>.
  16. ;
  17. ;    Truchet  - a script to create Truchet patterns
  18. ;                 by Adrian Likins <aklikins@eos.ncsu.edu>
  19. ;                 http://www4.ncsu.edu/~aklikins/
  20. ;    version about .8 give or take
  21. ;
  22. ;  Lots of thanks to Quartic for his help.
  23. ;
  24. ;
  25. ;         The utility of this script is left as an exercise for the reader.
  26. ;
  27. ;  NOTE: This script works best with even values for 'thickness'.
  28.  
  29. (define (center-ellipse img cx cy rx ry op aa feather frad)
  30.   (gimp-ellipse-select img (- cx rx) (- cy ry) (+ rx rx ) (+ ry ry )
  31.                        op aa feather frad)
  32. )
  33.  
  34. (define (use-tiles img drawable height width img2 drawable2 xoffset yoffset)
  35.   (gimp-edit-copy drawable2)
  36.   (let ((floating-sel (car (gimp-edit-paste drawable FALSE))))
  37.     (gimp-layer-set-offsets floating-sel xoffset yoffset)
  38.     (gimp-floating-sel-anchor floating-sel)
  39.   )
  40. )
  41.  
  42.  
  43. (define (create-tiles img drawable1 drawable2 size thickness backcolor forecolor)
  44.   (let* (
  45.         (half-thickness (/ thickness 2))
  46.         (outer-radius (+ (/ size 2) half-thickness))
  47.         (inner-radius (- (/ size 2) half-thickness))
  48.         )
  49.  
  50.     (gimp-selection-all img)
  51.     (gimp-context-set-background backcolor)
  52.     (gimp-edit-fill drawable1 BACKGROUND-FILL)
  53.  
  54.     (let* (
  55.           (tempSize (* size 3))
  56.           (temp-img (car (gimp-image-new tempSize tempSize RGB)))
  57.           (temp-draw (car (gimp-layer-new temp-img tempSize tempSize RGB-IMAGE "Jabar" 100 NORMAL-MODE)))
  58.          )
  59.       (gimp-image-undo-disable temp-img)
  60.       (gimp-image-add-layer temp-img temp-draw 0)
  61.       (gimp-context-set-background backcolor)
  62.       (gimp-edit-fill temp-draw BACKGROUND-FILL)
  63.  
  64.  
  65.       (center-ellipse temp-img size size outer-radius outer-radius CHANNEL-OP-REPLACE TRUE FALSE 0)
  66.       (center-ellipse temp-img size size inner-radius inner-radius CHANNEL-OP-SUBTRACT TRUE FALSE 0)
  67.  
  68.       (center-ellipse temp-img (* size 2) (*  size 2)  outer-radius outer-radius CHANNEL-OP-ADD TRUE FALSE 0)
  69.       (center-ellipse temp-img (* size 2) (*  size 2)  inner-radius inner-radius CHANNEL-OP-SUBTRACT TRUE FALSE 0)
  70.       (gimp-context-set-background forecolor)
  71.       (gimp-edit-fill temp-draw BACKGROUND-FILL)
  72.  
  73.       (gimp-selection-none temp-img)
  74.  
  75.       (gimp-image-resize temp-img size size (- size) (- size))
  76.       ; woo hoo it works....finally...
  77.  
  78.  
  79.       (gimp-selection-all temp-img)
  80.       (gimp-edit-copy temp-draw)
  81.       (let ((floating-sel (car (gimp-edit-paste drawable2 FALSE))))
  82.         (gimp-floating-sel-anchor floating-sel))
  83.  
  84.  
  85.       (let ((floating-sel (car (gimp-edit-paste drawable1 FALSE))))
  86.         (gimp-floating-sel-anchor floating-sel))
  87.  
  88.       (let ((drawble (car (gimp-drawable-transform-flip-simple drawable1
  89.                              ORIENTATION-VERTICAL TRUE 0 TRUE)))))
  90.  
  91.  
  92.       ;(gimp-display-new temp-img)
  93.       (gimp-image-delete temp-img)
  94.     )
  95.   )
  96. )
  97.  
  98.  
  99. (define (script-fu-truchet size thickness backcolor forecolor xtiles ytiles)
  100.   (let* (
  101.         (width (* size xtiles))
  102.         (height (* size ytiles))
  103.         (img (car (gimp-image-new width height RGB)))
  104.         (tile (car (gimp-image-new size size RGB)))
  105.         (layer-one (car (gimp-layer-new img width height
  106.                                         RGB-IMAGE "Rambis" 100 NORMAL-MODE)))
  107.         (tiledraw1 (car (gimp-layer-new tile size size
  108.                                         RGB-IMAGE "Johnson" 100 NORMAL-MODE)))
  109.         (tiledraw2 (car (gimp-layer-new tile size size
  110.                                         RGB-IMAGE "Cooper" 100 NORMAL-MODE)))
  111.         (Xindex 0)
  112.         (Yindex 0)
  113.         )
  114.  
  115.     (gimp-context-push)
  116.  
  117.     (gimp-image-undo-disable img)
  118.     (gimp-image-undo-disable tile)
  119.  
  120.     (gimp-image-add-layer img layer-one 0)
  121.     (gimp-image-add-layer tile tiledraw1 0)
  122.     (gimp-image-add-layer tile tiledraw2 0)
  123.  
  124.  
  125.     ;just to look a little better
  126.     (gimp-selection-all img)
  127.     (gimp-context-set-background backcolor)
  128.     (gimp-edit-fill layer-one BACKGROUND-FILL)
  129.     (gimp-selection-none img)
  130.  
  131.     (create-tiles tile tiledraw1 tiledraw2 size thickness backcolor forecolor)
  132.  
  133.  
  134.     (while (<= Xindex xtiles)
  135.       (while (<= Yindex ytiles)
  136.         (if (= (rand 2) 0)
  137.             (use-tiles img layer-one height width tile tiledraw1 (* Xindex size) (* Yindex size))
  138.             (use-tiles img layer-one height width tile tiledraw2 (* Xindex size) (* Yindex size))
  139.         )
  140.         (set! Yindex (+ Yindex 1))
  141.       )
  142.       (set! Yindex 0)
  143.       (set! Xindex (+ Xindex 1))
  144.     )
  145.  
  146.  
  147.     (gimp-image-delete tile)
  148.     (gimp-image-undo-enable img)
  149.     (gimp-display-new img)
  150.  
  151.     (gimp-context-pop)
  152.   )
  153. )
  154.  
  155. (script-fu-register "script-fu-truchet"
  156.   _"T_ruchet..."
  157.   _"Create an image filled with a Truchet pattern"
  158.   "Adrian Likins <aklikins@eos.ncsu.edu>"
  159.   "Adrian Likins"
  160.   "1997"
  161.   ""
  162.   SF-ADJUSTMENT _"Block size"        '(32 2 512 1 10 1 1)
  163.   SF-ADJUSTMENT _"Thickness"         '(2 1 512 1 10 1 1)
  164.   SF-COLOR      _"Background color"  "white"
  165.   SF-COLOR      _"Foreground color"  "black"
  166.   SF-ADJUSTMENT _"Number of X tiles" '(5 1 512 1 10 1 1)
  167.   SF-ADJUSTMENT _"Number of Y tiles" '(5 1 512 1 10 1 1)
  168. )
  169.  
  170. (script-fu-menu-register "script-fu-truchet"
  171.                          "<Image>/File/Create/Patterns")
  172.